﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BusinessLogic;
using System.Data.SqlClient;
using System.Data;

namespace DataAccessLogic
{
    public static class EmailTypeDataAccess
    {
        #region Methods
        public static EmailType BindDataToEmailType(DataRow row)
        {
            return CodeTableDataAccess.BindRowToCodeTable<EmailType>(row);
        }

        public static void Create(EmailType emailType)
        {
            if(emailType != null)
            {
                CodeTableDataAccess.Create<EmailType>(StoredProcedures.USP_EMAILADDRESSTYPECODE_CREATE, emailType.Description);
            }
        }

        public static void Delete(EmailType emailType)
        {
            Delete(emailType.ID);
        }

        public static void Delete(Guid id)
        {
            List<Exception> exes = CodeTableDataAccess.Delete<EmailType>(StoredProcedures.USP_EMAILADDRESSTYPECODE_DELETE, id);

            if (exes != null && exes.Count > 0)
            {
                throw exes[0];
            }
        }

        public static DataTable GetAll()
        {
            return CodeTableDataAccess.GetAll(StoredProcedures.USP_EMAILADDRESSTYPECODE_GETALL);
        }

        public static DataRow GetByID(Guid id)
        {
            return CodeTableDataAccess.GetByID(StoredProcedures.USP_EMAILADDRESSTYPECODE_GETBYID, id);
        }

        public static void Update(EmailType emailType)
        {
            if(emailType != null)
            {
                CodeTableDataAccess.Update<EmailType>(StoredProcedures.USP_EMAILADDRESSTYPECODE_UPDATE, emailType.ID, emailType.Description);
            }
        }
        #endregion
    }
}